/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 手持道具数据
	/// module : structs
	/// </summary>
	public class ItemPortablePOD : IPOD 
    {
        public readonly static Func<ItemPortablePOD> FACTORY = () => new ItemPortablePOD();
		public static Func<ItemPortablePOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        ///  等级
        /// </summary>
		public int level;
		/// <summary>
        ///  解锁部分
        /// </summary>
        private List<int> m_parts;
		
		
        public List<int> parts
        {
            get
            {
                if(m_parts == null)
                {
                    m_parts = new();
                }
                return m_parts;
            }
            private set => m_parts = value;
        }
        public List<int> unsafe_parts
        {
        	get => m_parts;
        	set => m_parts = value;
        }
		
		/*-- constructors --*/
		public ItemPortablePOD() {}
		public ItemPortablePOD(int level, List<int> parts) {
			this.level = level;
			this.m_parts = parts;
		}
		  public void Serial(SOutputStream _out) {
                if(level != default) {
                    _out.WriteByte(1);
                    _out.Write_int(level);
                }
                if(m_parts != default) {
                    _out.WriteByte(2);
                    _out.Write_list_int(m_parts);
                } 
        }
            
        public void UnSerial(SInputStream _in) {
            while (_in.HasRemaining())
            {
                int _key = _in.ReadByte();
                switch (_key)
                {
                    case 1:
                        level = _in.Read_int();
                        break;
                    case 2:
                        m_parts = _in.Read_list_int();
                        break;
                    default: _in.SkipBinary();break;
                }
            }
        }
		
		public ItemPortablePOD Clone() {
            ItemPortablePOD o = DynamicFactory();
            o.level = level;
            if (m_parts != null) {
                o.m_parts = new (m_parts);
            }
            return o;
        }
        
        public void Clear() {
            level = default;
            m_parts = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "ItemPortablePOD [";
			str += "level=";
			str += level;
			str += ", parts=";
			str += m_parts.ToString<int>();
			str += "]";
			return str;
		}
		
	}
}